package com.demo.study.behavior.inbound.handler;

import com.demo.study.behavior.inbound.Handler;
import com.demo.study.behavior.inbound.dto.InboundApplication;

import java.util.List;
import java.util.stream.Collectors;

import static com.demo.study.behavior.inbound.dto.InboundApplication.DOA_DAP_RETURN;

/**
 * 退换货执行者
 *
 * @author Baymax
 * @since 2022/3/25
 */
public class DoaDapHandler implements Handler {
    private List<InboundApplication> applications;

    public DoaDapHandler(List<InboundApplication> applications) {
        this.applications = applications;
    }

    @Override
    public boolean needExecute() {
        applications = applications.stream()
            .filter(application -> DOA_DAP_RETURN.equals(application.getReturnType()))
            .collect(Collectors.toList());
        return applications.size() > 0;
    }

    @Override
    public void execute(List<String> businessIds) {
        System.out.println("退换货返还的数据：" + String.join(",", businessIds));
        System.out.println(applications);
    }

    @Override
    public List<InboundApplication> getApplications() {
        return this.applications;
    }
}
